package com.sofwin.interceptor;/**
 * @PackageName:com.sofwin.interceptor
 * @author:andyLiu
 * @DateTime:2020/12/30 17:01
 * @Description:[TODO]输入当前模块作用
 **/

import com.sofwin.Constants;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @ClassName: LoginInterceptor
 * @Description: TODO
 * @Author: andyliu
 * @Date: 2020/12/30 17:01
 * @Version: 1.0
 **/
public class LoginInterceptor implements HandlerInterceptor {
    /**
     * 请求进入handler前执行
     * @param request
     * @param response
     * @param handler
     * @return
     * @throws Exception
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        Object obj = session.getAttribute(Constants.CURR_USER_SESSIONKEY);
        if(obj!=null){
            return true;
        }
        response.sendRedirect(request.getContextPath()+"/system/login");
        return false;
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {

    }
}
